//
//  HEBindInputCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2021/5/5.
//  Copyright © 2021 honglutec. All rights reserved.
//

#import "HEBindInputCell.h"

@interface HEBindInputCell ()<QMUITextFieldDelegate>

@property(nonatomic, strong) UILabel *titleLb;
@property(nonatomic, strong) QMUITextField *contentTf;
@property(nonatomic, assign) NSInteger row;
@property(nonatomic, strong) UITapGestureRecognizer *tap;

@property(nonatomic, strong) UIView *leftWarp;
@end

@implementation HEBindInputCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
 
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    _titleLb = [UILabel new];
    _titleLb.font = DYFont(17);
    _titleLb.text = @"所在地区";
    [self.contentView addSubview:_titleLb];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.width.mas_offset([_titleLb.text widthForFont:DYFont(15)] + 10);
    }];
    
    _contentTf = [[QMUITextField alloc] init];
    _contentTf.maximumTextLength = 500;
    _contentTf.placeholder = @"请输入内容";
    _contentTf.font = DYFont(17);
    _contentTf.layer.cornerRadius = 3;
    _contentTf.textInsets = UIEdgeInsetsMake(0, 10, 0, 10);
    _contentTf.clearButtonMode = UITextFieldViewModeNever;
    _contentTf.delegate = self;
    [self.contentView addSubview: _contentTf];
    _contentTf.layer.borderWidth = 1;
    _contentTf.layer.borderColor = CSplitLineColor.CGColor;
    _contentTf.userInteractionEnabled = YES;
    
    [_contentTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(10);
        make.left.equalTo(_titleLb.mas_right).mas_offset(5);
        make.right.equalTo(self.contentView).mas_offset(-10);
        make.height.mas_offset(36);
        make.bottom.equalTo(self.contentView).mas_offset(-10);
    }];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
   self.fiterModel = fiterModel;
   self.formModel = formModel;

   _titleLb.text = fiterModel.leftTitle;
 
   _contentTf.placeholder = fiterModel.placeHolder;
   _contentTf.text = formModel.rp_title;
   _contentTf.enabled = fiterModel.enable;
   _contentTf.keyboardType = fiterModel.keyboardType;

   _contentTf.text = [formModel valueForKey:fiterModel.tableKey];
}

- (void)configCellWithModel:(id)model fiterModel:(GDFiterCellModel *)fiterModel indexPath:(NSIndexPath *)indexPath {
   [self refreshContent:fiterModel formModel:self.formModel indexPath:indexPath];
}

#pragma mark - TextFiledDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
   NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
   [self.formModel setValue:text forKey:self.fiterModel.tableKey]; //  值赋给_formModel
   return YES;
}

@end
